package com.j.lemon.learn.thread.produc1consum;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @Author lijunjun
 * @Date 2019-10-24 10:40
 * @Description
 */
public class ProductConsumer1 {


    private static void p(Object o) throws InterruptedException {
        synchronized (o) {
            o.notify();
            System.out.println(Thread.currentThread().getName() + "product");
            o.wait();
        }
    }

    private static void c(Object o) throws InterruptedException {
        synchronized (o) {
            o.notify();
            System.out.println(Thread.currentThread().getName() + "consumer");
            o.wait();
        }
    }

    public static void main(String[] args) {
        BunShop bunShop = new BunShop(1);
        new Thread(() -> {
            try {
                bunShop.consumer();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread(() -> {
            try {
                bunShop.product();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();


    }
}

class BunShop {
    private int serviceCount;
    private static Object lock = new Object();
    List<Integer> list = new ArrayList<>(serviceCount);

    BunShop(int serviceCount) {
        this.serviceCount = serviceCount;
    }

    void product() throws InterruptedException {
        while (true) {
            Thread.sleep(1000L);
        }

    }

    void consumer() throws InterruptedException {
        while (true) {

        }
    }
}
